<?php
use backend\assets\AgentAsset;
use yii\bootstrap\ActiveForm;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\LinkPager;

AgentAsset::register($this);
?>
<div class="hide"><iframe name='send_post' id='send_post'></iframe></div>
<div class="mg20-y" style="padding-left: 16px;">
	<form action="<?=Url::toRoute(['financial/cashier'])?>" method="get">
	<input class="mr20" type="hidden" name="action" value="healthcardlist" />
        <input class="lh45" type="text" placeholder="输入疗程卡名称" style="width: 224px;height: 42px;line-height: 42px;" name="title" value="<?=\Yii::$app->request->get('title')?>"/>
        <span class="btnBg ml20" style=" height: 40px;">
			<input type="submit"  value="搜索" style="height: 40px;line-height: 40px; background: 0; border: 0; "/>
		</span>
    </form>
</div>
<div class="row">
    <table class="table table-bordered">
        <thead>
            <tr>
                <th>疗程卡名称</th>
                <th>次数</th>
                <th>操作</th>
            </tr>
        </thead>

        <tbody>
            <tr>
                <td class="text-center" colspan="3"><a class="add-recharge" href="javascript:;"><img class="mr10" src="<?=Yii::getAlias('@web/backend/img/financial/addnew.png');?>" alt=""/>添加新卡</a></td>
            </tr>
            <?php foreach($list as $r):?>
                <tr style="cursor: pointer;">
                    <?php ActiveForm::begin(['action'=>Url::toRoute(['financial/cashier','action'=>'updatehealthcard']),'options'=>['target'=>'send_post']]);?>
                    <td>
                        <span class="name">
                        <input type="text" value="<?=Html::encode($r['config_key'])?>" name="key" class="read-only username" style="width: 100%; height: 40px; line-height: 40px; border: 1px solid #e5e5e5 ; padding-left: 12px;" readonly>
                        </span>
                    </td>
                    <td><?=Html::encode($r['config_val'])?></td>
                    <td>
                        <a class="btn btn-sm btn-borB4 editBtn" href="javascript:;" data-id="<?=$r['config_id']?>">编辑</a>
                        <a class="chooseBtn btn btn-sm btn-success hide" href="javascript:;" data-price="<?=$r['config_val2'] ?>" data-id="<?=$r['config_id']?>">选择</a>
                        <input type="hidden" name="id" value="<?=$r['config_id']?>"/>
                        <input type="hidden" name="val" value="<?=$r['config_val']?>">
                        <div class="fadeBox" style="display:none;">
                            <input type="submit" class="edit btn btn-sm btn-borB cet" value="保存" />
                            <a href="#" class="edit rest btn btn-sm btn-borB1">取消</a>
                        </div>
                    </td>
                    <?php ActiveForm::end();?>
                </tr>
			<?php endforeach;?>
            <tr class="lastTr" style="display: none;">
                <?php ActiveForm::begin(['action'=>Url::toRoute(['financial/cashier','action'=>'addhealthcard']),'options'=>['target'=>'send_post']]);?>
                    <td><input type="text" id="username" name="key"></td>
                    <td><input type="text" id="price" name="val"></td>
                    <td>
                        <input type="submit" value="保存" onclick="return checkTest()" class="edit red btn btn-sm btn-borB" /></a><a href="javascript:;" class="edit restb red btn btn-sm btn-borB1" style="margin-left: 5px;">取消</a>
                    </td>
                    <?php ActiveForm::end();?>
            </tr>
        </tbody>
    </table>
    <div class="page" style="text-align:center;">
                   <?=LinkPager::widget([   
					    'pagination' => $page,
						'firstPageLabel' => '首页',
						'nextPageLabel' => '下一页',
						'prevPageLabel' => '上一页',
						'lastPageLabel' => '末页',
					    'hideOnSinglePage'=>false
					]); ?>
                </div>

</div>

<script>
    $(document).ready(function(){
        var $product_id = document.getElementsByClassName('username');
        var $subMit = document.getElementsByClassName('cet');
        for (var i = 0, j = $subMit.length; i < j; i++){
            //scope2 作用域2
            var $set = $subMit[i];
            $set.onclick = function(i) {
                //scope3 作用域3
                return function () {
                    //scope4 作用域4
                    if (i < $product_id.length) {
                        var $key = $product_id[i];
                        if ($key.value == 0) {
                            layer.alert('请输入疗程卡名称', {
                                icon: 2,
                                shade: 0.2
                            });
                            return false
                        }
                        else if ($key.value.length > 7) {
                            layer.alert('疗程卡名称不能超过7个字', {
                                icon: 2,
                                shade: 0.2
                            });
                            return false
                        }
                    }
                }

            }(i)
        }
    });
</script>
<?php $this->beginBlock('js_index_end') ?>
$(function(){
    $('.table tr').dblclick(function(){
        var $this = $(this);
        $this.find('input[type="text"]').removeClass('read-only').removeAttr('readonly');
        $this.find('.fadeBox').show();
        $this.find('.editBtn').hide()
        })

    $('.rest').click(function(e){
        e.stopPropagation();
        $(this).parent().hide();
        $(this).parent().parent().find('.editBtn').show();
        $(this).parent().parent().parent().removeClass('current')
        $(this).parent().parent().parent().find('input[type="text"]').addClass('read-only').attr('readonly',true);
    })

    $('.editBtn').click(function(e){
        e.stopPropagation();
        $(this).hide();
        $(this).siblings().show();
        $(this).find('.fadeBox').show();
        $(this).parent().parent().addClass('current')
        $(this).parent().parent().siblings().removeClass('current')
        $(this).parent().parent().find('input[type="text"]').removeClass('read-only').removeAttr('readonly');
        $(this).parent().parent().find('span input[type="text"] ').removeClass('read-only').removeAttr('readonly');
    })

    $('.add-recharge').click(function(e){
        e.stopPropagation();
        $('.lastTr').show();
        $('.lastTr').addClass('current')
    })
    $('.restb').click(function(e){
        e.stopPropagation();
        $('.lastTr').hide();
    })
    $('.lastTr input').click(function(e){
        e.stopPropagation();
    })
});
    function checkTest(){
    var $supplier_id = $('#username').val()
    if ($supplier_id == 0){
    layer.alert('请输入疗程卡名称', {
    icon: 2,
    shade: 0.2,
    });
    return false
    }
    else if ($supplier_id.length > 7) {
    layer.alert('疗程卡名称不能超过7个字', {
    icon: 2,
    shade: 0.2,
    });
    return false
    }
    var $supplier_contact = $('#price').val()
    if ($supplier_contact == 0){
    layer.alert('请输入次数', {
    icon: 2,
    shade: 0.2,
    });
    return false
    }
    else if ( $supplier_contact !='' && !/^\d{0,2}$/.test($supplier_contact)) {
    layer.alert('请输入不超过2位的数字 ', {
    icon: 2,
    shade: 0.2,
    });
    return false
    }
    }


<?php $this->endBlock() ?>
<?php $this->registerJs($this->blocks['js_index_end'], $this::POS_END); ?>

<?php $this->registerJsFile("@web/system/financial/cashier/healthcard.js",['position'=>$this::POS_END]);?>